package cui;

import gui.EshopGUIclient;
import gui.ShopFassade;

import java.io.*;
import java.net.*;
//import java.util.*;

import logik.ShopInterface;

public class EshopClient {
	
	private ShopInterface eshopmanager;
	
	public static final int DEFAULT_PORT = 6789;
	
	private Socket socket = null;
	private BufferedReader in;
	private PrintStream out;
	
	public EshopClient(String datei, String host, int port) {
		try {
            eshopmanager = new ShopFassade(host, port);
        } catch (IOException e) {

            e.printStackTrace();
        }
	}
	
	private void warenAusgeben() {
		out.println("warenAusgeben");
		try {
			int laenge = in.read();
			for(int i = 0; i <= laenge; i++) {
				String art = in.readLine();
				System.out.println(art);
			}
		} catch (IOException e) {
			System.out.println("Fehler beim Waren ausgeben.");
			}
		}
	
	private void quit() {
		out.println("quit");
		try {
			socket.close();
		} catch (IOException ioe) { /* Fehlerbehandlung */ }
	}
	
	public static void main(String[] args) {
		int port = 0;
        String host = null;
        InetAddress ia = null;
        
        if (args.length > 2) {
            System.out.println("Aufruf: java <Klassenname> [<hostname> [<port>]]");
            System.exit(0);
        }
        if (args.length == 0) {
            try {
                ia = InetAddress.getLocalHost();
            } catch (Exception e) {
                System.out.println("XXX InetAdress-Fehler: " + e);
                System.exit(0);
            }
            host = ia.getHostName(); // host ist lokale Maschine
            port = DEFAULT_PORT;
        }
        if (args.length == 1) {
            port = DEFAULT_PORT;
            host = args[0];
        }

        if (args.length == 2) {
            host = args[0];
            try {
                port = Integer.parseInt(args[1]);
            } catch (NumberFormatException e) {
                System.out.println("Aufruf: java ShopGui [<hostname> [<port>]]");
                System.exit(0);
            }
        }

        final int port1 = port;
        final String host1 = host;

        		//EshopGUIclient gui = new EshopGUIclient();
        		new EshopClient("Shop", host1, port1);
	}
	
}